#include "../../odb/user.hxx"
#include "../../common/data_mysql.hpp"
#include "../../common/logger.hpp"
#include "user-odb.hxx"
#include <memory>
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式，false-调试； true-发布；");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

void insert(zrb::userTable& user)
{
    auto user1 = std::make_shared<zrb::User>("uid1","昵称1","2825280463");
    user.insert(user1);

    auto user2 = std::make_shared<zrb::User>("uid2","13235262021");
    user.insert(user2);
}

void update_by_id(zrb::userTable& user,const std::string& id)
{
    auto res1 = user.select_by_user_id(id);
    res1->description("你一副不缺我的样子，怎么让我在你身边停留");
    user.update(res1);
}

void update_by_phone(zrb::userTable& user,const std::string& phone)
{
    auto res1 = user.select_by_phone(phone);
    res1->password("123456");
    user.update(res1);
}

void update_by_nickname(zrb::userTable& user,const std::string& name)
{
    auto res1 = user.select_by_nickname(name);
    res1->nickname("昵称2");
    user.update(res1);
}

void select_user(zrb::userTable& user,const std::vector<std::string>& id_list)
{
    auto res = user.select_multi_id(id_list);
    for(auto e : res)
    {
        std::cout << e.nickname() << std::endl;
    }
}

int main(int argc, char *argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    zrb::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto db = zrb::ODBFactory::create(1,"root","2825280463zZ",
        "UserTest","127.0.0.1",3306,"utf8");

    zrb::userTable user(db);
    // insert(user);
    // update_by_id(user,"uid1");
    // update_by_phone(user,"13235262021");
    // update_by_nickname(user,"uid2")
    std::vector<std::string> id_list = {"uid1","uid2"};
    select_user(user,id_list);

    return 0;
}

